/*
 * @Descripttion: 
 * @version: 
 * @Author: cyj
 * @Date: 2023-03-21 22:19:54
 */
let big = [1, 3, 5, 7, 8, 10, 12] //31
let small = [4, 6, 9, 11] //30

//导出格式化时间函数
export function formatDate(time) {
  let sendTime = new Date(time);
  let nowTime = new Date()
  //获取某一用户发送信息的具体时间
  let h = sendTime.getHours()
  let m = sendTime.getMinutes()
  let Y = sendTime.getFullYear()
  let M = sendTime.getMonth() + 1
  let D = sendTime.getDate() //某天
  let DD = sendTime.getDay() //周几

  //获取当前时间
  let nh = nowTime.getHours()
  let nm = nowTime.getMinutes()
  let nY = nowTime.getFullYear()
  let nM = nowTime.getMonth() + 1
  let nD = nowTime.getDate()

  //同一天
  if (D == nD && M == nM && Y == nY) {
    if (m < 10)
      m = '0' + m
    //凌晨
    if (0 <= h && h < 6) {
      return '凌晨' + h + ':' + m
    }
    if (6 <= h && h < 12)
      return '早上' + h + ':' + m
    if (12 <= h && h < 18)
      return '下午' + h + ':' + m
    if (18 <= h && h < 24)
      return '晚上' + h + ':' + m
  }
  //同月份昨天
  else if (D === nD - 1 && M === nM && Y === nY)
    return '昨天'
  //同月份前天
  else if (D === nD - 2 && M === nM && Y === nY)
    return '周' + DD
  //同一月份超过两天
  else if ((nD - D > 2) && M === nM && Y === nY)
    return M + '月' + D + '日'
  //不同月份
  else if (M == nM - 1 && Y == nY) {
    if ((D == 30 && nD == 1) && small.indexOf(M) != -1) {
      return '昨天' + h + ":" + m
    } else if ((D == 31 && nD == 1) && big.indexOf(M) != -1) {
      return '昨天' + h + ":" + m
    } else if ((D == 28 || D == 29) && nD == 1 && M == 2) {
      return '昨天' + h + ":" + m
    } else if ((D == 30 && nD == 2) && small.indexOf(M) != -1) {
      return '前天' + h + ":" + m
    } else if ((D == 31 && nD == 2) && big.indexOf(M) != -1) {
      return '前天' + h + ":" + m
    } else return M + '月' + D + '日'
  }
  //不同年
  else if (Y != nY) {
    return Y + '年' + M + '月' + D + '日'
  }
}

//聊天时间
export function formatTime(time) {
  let sendTime = new Date(time);
  let nowTime = new Date()
  //获取某一用户发送信息的具体时间
  let h = sendTime.getHours()
  let m = sendTime.getMinutes()
  let Y = sendTime.getFullYear()
  let M = sendTime.getMonth() + 1
  let D = sendTime.getDate() //某天
  let DD = sendTime.getDay() //周几

  //获取当前时间
  let nh = nowTime.getHours()
  let nm = nowTime.getMinutes()
  let nY = nowTime.getFullYear()
  let nM = nowTime.getMonth() + 1
  let nD = nowTime.getDate()

  //同一天
  if (D == nD && M == nM && Y == nY) {
    if (m < 10)
      m = '0' + m
    //凌晨
    if (0 <= h && h < 6) {
      return '凌晨' + h + ':' + m
    }
    if (6 <= h && h < 12)
      return '早上' + h + ':' + m
    if (12 <= h && h < 18)
      return '下午' + h + ':' + m
    if (18 <= h && h < 24)
      return '晚上' + h + ':' + m
  }
  //同月份昨天
  else if (D === nD - 1 && M === nM && Y === nY) {
    if (h < 10) h = '0' + h
    if (m < 10) m = '0' + m
    return '昨天' + h + ':' + m
  }
  //同月份前天
  else if (D === nD - 2 && M === nM && Y === nY) {
    if (DD == 1) return '周一'
    if (DD == 2) return '周二'
    if (DD == 3) return '周三'
    if (DD == 4) return '周四'
    if (DD == 5) return '周五'
    if (DD == 6) return '周六'
    if (DD == 7) return '周日'
  }

  //同一月份超过两天
  else if ((nD - D > 2) && M === nM && Y === nY)
    return M + '月' + D + '日'

  //不同月份
  else if (M == nM - 1 && Y == nY) {
    if ((D == 30 && nD == 1) && small.indexOf(M) != -1) {
      return '昨天' + h + ":" + m
    } else if ((D == 31 && nD == 1) && big.indexOf(M) != -1) {
      return '昨天' + h + ":" + m
    } else if ((D == 28 || D == 29) && nD == 1 && M == 2) {
      return '昨天' + h + ":" + m
    } else if ((D == 30 && nD == 2) && small.indexOf(M) != -1) {
      return '前天' + h + ":" + m
    } else if ((D == 31 && nD == 2) && big.indexOf(M) != -1) {
      return '前天' + h + ":" + m
    } else return M + '月' + D + '日' + '\t' + h + ':' + m
  }
  //不同年
  else if (Y != nY) {
    return Y + '年' + M + '月' + D + '日'
  }
}


export function formatSignTime(time) {
  let date = new Date(time) //转换为时间对象
  //获取某一用户发送信息的具体时间
  let s = (date.getMinutes() < 10 ? '0' + (date.getSeconds()) : date.getSeconds()) //秒
  let h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) //时
  let m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) //分
  let Y = date.getFullYear() //年
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
  return Y + '-' + M + '-' + D + '\t' + h + ':' + m + ':' + s
}

//导出年月日
export function fileName(time) {
  let date = new Date(time) //转换为时间对象
  //获取某一用户发送信息的具体时间
  let Y = date.getFullYear() //年
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
  return Y + M + D
}

//格式化化生日
export function formatBirth(time) {
  let date = new Date(time) //转换为时间对象
  //获取某一用户发送信息的具体时间
  let Y = date.getFullYear() //年
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
  return Y + '-' + M + '-' + D
}
